<?php
declare (strict_types = 1);

namespace app\middleware;

use think\facade\Cache;

class UniAccount
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        // todo 从redis中获取平台id: uniacid 
        
        // $redis = Cache::store('redis')->handler();
        
        // $uniacid = $redis->get('uniacid');
        $auth = $request->auth;
        $uid = $auth['user_id'];
        // $uniacid = current_uni_account( $uid );
        $uniacid = get_uniacid( $uid );

        if( !$uniacid ){

            return json([
                'code'      => 10,
                'message'   => '请先选择平台',
            ]);

        }

        return $next( $request );
    }
}
